perm filename NETFNG.FAI[SAI,LES]1 blob sn#813558 filedate 1986-03-28 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00005 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	 DATBEG CMDBUF HSTBUF SAVJFF SAVJRL DATEND NETFNG HSTCPY NULHST CMDCPY NULCMD
C00005 00003	 CMDSND CMDLOD GETREP
C00008 00004	 TTLCST TTYLOC TTYLUZ
C00010 00005	 FAIRET SUCRET NIORTS ERRTNS HSTTAB
C00012 ENDMK
C⊗;
;⊗ DATBEG CMDBUF HSTBUF SAVJFF SAVJRL DATEND NETFNG HSTCPY NULHST CMDCPY NULCMD

TITLE NETFNG Network hacking for FINGER
SUBTTL Mark Crispin, August 1978

COMMENT ⊗ Changes:

May/Jun 83 JJW	Changes for IP/TCP.
29-Jan-83  JJW	No longer calls UNMHST, and doesn't MAPHST if HSTADR already
		set.  This for multiple host Finger.

end of comment ⊗

INTERN NETFNG

; Data area

DATBEG←←.
CMDBUF:	BLOCK =50			; command buffer
HSTBUF:	BLOCK =20			; host name buffer
SAVJFF:	BLOCK 1				; save of JOBFF
SAVJRL:	BLOCK 1				; save of old core size
DATEND←←.-1

; flag←NETFNG(command-string,host-string)
; FLAG is -1 if success, 0 on error.

NETFNG:	SETZM DATBEG
	MOVE [DATBEG,,DATBEG+1]
	BLT DATEND			; clear data area
	POP 16,1			; 1 ← host name byte pointer
	POP 16,2			; 2 ← character count
	MOVEI 2,(2)			; flush SAIL cruft
	JUMPE 2,NULHST
	MOVE 3,[440700,,HSTBUF]
HSTCPY:	ILDB 1 ↔ IDPB 3			; copy string
	SOJG 2,HSTCPY
NULHST:	POP 16,1			; 1 ← command byte pointer
	POP 16,2			; 2 ← character count
	MOVEI 2,(2)			; flush SAIL cruft
	MOVE 3,[440700,,CMDBUF]
	JUMPE 2,NULCMD
CMDCPY:	ILDB 1 ↔ IDPB 3			; copy string
	SOJG 2,CMDCPY
NULCMD:	MOVEI 15 ↔ IDPB 3		; save a CR
	MOVEI 12 ↔ IDPB 3		; and an LF

; Hack the world since SAIL throws a fit otherwise

	IOPUSH				; save I/O channels 0 and 1
	 JRST 4,.-1
	IOPUSH 1,
	 JRST 4,.-1
	HRRZ JOBREL↑			; top of real core
	MOVEM SAVJRL			; so we can smallify later
	EXCH JOBFF↑			; start I/O there despite cretin SAIL
	MOVEM SAVJFF			; save SAIL's idea though

; falls through
;⊗ CMDSND CMDLOD GETREP

; Try to find host name

	SKIPN HSTADR		;Skip if already have host table
	PUSHJ 17,MAPHST			; map in host table
	MOVEI HSTBUF
	PUSHJ 17,HSTNAM			; get HDB for this host
	 JRST [	OUTSTR [ASCIZ/No such host: /]
		OUTSTR HSTBUF
		OUTSTR [ASCIZ/
/]
		JRST FAIRET]
	 JRST [	OUTSTR [ASCIZ/Ambiguous host name: /]
		OUTSTR HSTBUF
		OUTSTR [ASCIZ/
/]
		JRST FAIRET]
	MOVEM HOST			; set up for CONECT

; Try to connect to FINGER server

	MOVEI 117			; FINGER socket
	MOVEM ICPSKT
	PUSHJ 17,CONECT			; connect to server
	 JRST [	PUSHJ 17,MTPERR ↔ JRST FAIRET]
	 JRST [	PUSHJ 17,NIOERR ↔ JRST FAIRET]
	SETZ
	SLEEP

; Got connection, now send string down

	MOVE 1,[440700,,CMDBUF]
	JRST CMDLOD
CMDSND: PUSHJ 17,NETOCH			; send character out
	 JRST [	PUSHJ 17,NIOERR ↔ JRST FAIRET]
CMDLOD:	ILDB 1				; get a character from command
	JUMPN CMDSND
	PUSHJ 17,NETSND			; force buffer out
	 JRST [	PUSHJ 17,NIOERR ↔ JRST FAIRET]

; Now get reply

GETREP:	MOVE 1,0		;Save previous char (JJW 9/85)
	PUSHJ 17,NETICW			; get a character of reply
	 JRST SUCRET
	CAIN 12			;Is this a LF?
	 JRST [	CAIE 1,15	;Yes, was previous a CR?
		 OUTCHR [15]	;No, insert one for $#&!% Unixes who forget
		JRST .+1]
	;JJW 3/84 translate to WAITS character set before typing
	CAIN 176			;tilde
	 MOVEI 32
	CAIN 175			;right-brace
	 MOVEI 176
	CAIN 33				;diamond
	 MOVEI 175
	OUTCHR				; type it
	JRST GETREP
;⊗ TTLCST TTYLOC TTYLUZ

; PTY location

; flag←TTYLOC(job-number-of-PTY-owner)
; FLAG is -1 if success, 0 on error.

INTERN TTYLOC

TTLCST:	BLOCK 21			; TTY location string

TTYLOC:	MOVE 1,-1(17)			; get job number of PTY owner
	POP 17,-1(17)			; clean up stack
	MOVEI 1				; 0 ← pntr to block starting at 0
	DMOVE 2,[-1,,137 ↔ 2]		; read one word from 137 to 2
	JOBRD
	 JRST TTYLUZ
	JUMPE 2,TTYLUZ			; must be non-zero with no LH
	TLNE 2,-1
	 JRST TTYLUZ
	HRLI 2,-21			; 1 leader + 20 text words
	MOVEI 3,TTLCST
	JOBRD
	 JRST TTYLUZ
	MOVE TTLCST
	CAME ['TERMID']
	 JRST TTYLUZ
	MOVEI 77776			; clear last two data bytes
	ANDCAM TTLCST+20
	OUTSTR TTLCST+1
	TDZA 1,1			; success
TTYLUZ:	 SETO 1,
	POPJ 17,
;⊗ FAIRET SUCRET NIORTS ERRTNS HSTTAB

; Returns and all that

FAIRET:	TDZA 1,1			; error return
SUCRET:	 SETO 1,			; success return
	IOPOP 1,			; restore channels 0 and 1
	 JRST 4,.-1
	IOPOP
	 JRST 4,.-1
	MOVE SAVJFF			; back where SAIL was
	MOVEM JOBFF↑			; restore SAIL's cretinism
	MOVE SAVJRL			; original core size
	CORE				; smallify
	 JFCL				; tried to be nice
	POPJ 17,

; Switches for NETWRK

NIORTS←←1				; network I/O routines
ERRTNS←←1				; error routines
HSTTAB←←1				; host table hacking
TTYSTS←←1				; terminal locations

; Insert wonderful network routines

.INSERT NETWRK.FAI[S,NET]
	INTERNAL HSTNUM,HSTADR,TTYSTR	; for SAIL code to use

END